package com.trade.wzj.common.yang;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.trade.wzj.model.xiang.SupplierInfo;
import com.trade.wzj.service.yang.SupplierInfoService_Yang;

@Controller
@RequestMapping("/SupplierInfoContrillerYang")
public class SupplierInfoController_Yang {
	
	@Resource(name="supplierInfo")
	private SupplierInfoService_Yang SupplierInfoService;

	public SupplierInfoService_Yang getSupplierInfoService() {
		return SupplierInfoService;
	}

	public void setSupplierInfoService(SupplierInfoService_Yang supplierInfoService) {
		SupplierInfoService = supplierInfoService;
	}
	
	@RequestMapping("/findSupplier")
	@ResponseBody
	public PageInfo<SupplierInfo> findSupplier(String name, Integer currentPages, Model model) {
		// 起始页数
		Integer currentPage = 1;
		// 每条显示的行数
		int rowPerPage = 5;
		PageInfo<SupplierInfo> pageInfo = null;
		// 结果集列表
		List<SupplierInfo> list = null;
		try {
			if (null != currentPages) {
				// 页码不为空时，将当前页信息赋值
				currentPage = currentPages;
			}
			PageHelper.startPage(currentPage, rowPerPage);
			list = SupplierInfoService.findSupplier(name);

			pageInfo = new PageInfo<>(list);
			
			System.out.println(list.size());
			System.out.println(pageInfo.getList());
			for (SupplierInfo supplierInfo : list) {
				System.out.println(supplierInfo);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return pageInfo;
	}
	
	//通过id查询供应商基本信息
	@RequestMapping("/getSupplierInfoById")
	@ResponseBody
	public SupplierInfo getSupplierInfoById(Integer id) {
		SupplierInfo sup = null;
		try {
			sup=SupplierInfoService.getSupplierInfoById(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sup;
	}
	
	//通过id修改供应商基本信息
	@RequestMapping("/updateSupplier")
	@ResponseBody
	public boolean updateSupplier(SupplierInfo supplier) {
		boolean bol=false;
		try {
			SupplierInfoService.updateSupplier(supplier);
			bol=true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return bol;
	}
}
